/*
  This file is part of Xynilex.

  Xynilex is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Xynilex is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Xynilex.  If not, see <http://www.gnu.org/licenses/>.
 */

// Xynilex Headers
#include "Client/GameManager.h"
#include "Common/Asserts.h"
#include "Graphics/Graphics.h"
#include "GUI/GUI.h"
#include "Sound/Sound.h"

using Xynilex::Client::GameManager;

GameManager::GameManager()
{
  this->mGraphicsManager = new Xynilex::Graphics::GraphicsManager();
  this->mGUIManager = new Xynilex::GUI::GUIManager();
  this->mSoundManager = new Xynilex::Sound::SoundManager();
}

GameManager::~GameManager()
{
  XyAssert(this->mGraphicsManager == NULL);
  XyAssert(this->mGUIManager == NULL);
  XyAssert(this->mSoundManager == NULL);
}

void GameManager::initialize()
{
  this->mGraphicsManager->initialize();
  this->mGUIManager->initialize(this->mGraphicsManager->getRenderWindow(), this->mGraphicsManager->getSceneManager());
  this->mSoundManager->initialize();
}

void GameManager::shutdown()
{
  XyAssert(this->mGraphicsManager != NULL);
  this->mGraphicsManager->shutdown();
  delete this->mGraphicsManager;
  this->mGraphicsManager = NULL;

  XyAssert(this->mGUIManager != NULL);
  this->mGUIManager->shutdown();
  delete this->mGUIManager;
  this->mGUIManager = NULL;

  XyAssert(this->mSoundManager != NULL);
  this->mSoundManager->shutdown();
  delete this->mSoundManager;
  this->mSoundManager = NULL;
}

void GameManager::run()
{
  this->mGraphicsManager->createWindow(false, 600, 600);
  this->mGUIManager->loadLayout("../Media/Layouts/HUD.layout");
  bool keepGoing = true;

  while(keepGoing)
  {
    keepGoing &= this->mGraphicsManager->renderFrame();
  }
}
